$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/merchant/list',
        datatype: "json",
        colModel: [
			{ label: '商户名称', name: 'name', index: 'name', width: 80 },
            { label: '店铺负责人', name: 'username', index: 'username', width: 65},
            { label: '所属代理商', name: 'saleid', index: 'saleid', width: 65,formatter: function(cellvalue, options, rowdata) {
                    var dlname = "";
                    $.ajax({
                        type: "POST",
                        async:false,
                        url: baseURL + "sys/agent/queryAgentBySaleid/"+rowdata.saleid,
                        success: function(r){
                            dlname = r.agent.username;
                        }
                    });
                    return dlname;
                }},
            { label: '所属业务员', name: 'businessname', index: 'businessname', width: 65},
            { label: '密码线条数', name: 'userid', index: 'userid', width: 80,formatter: function(cellvalue, options, rowdata) {
                    var num = 0;
                    $.ajax({
                        type: "POST",
                        async:false,
                        url: baseURL + "sys/merchant/queryLineCodeNum/"+rowdata.userid,
                        success: function(r){
                            num = r.num;
                        }
                    });
                    return num;
                } },
            { label: '分佣比例', name: 'businessRatio', index: 'businessRatio', width: 80 },
			{ label: '详细地址', name: 'address', index: 'ADDRESS', width: 80 },
			{ label: '店铺电话', name: 'shopPhone', index: 'SHOP_PHONE', width: 60 },
            { label: '操作', name: 'sy', width: 60,align:'center',formatter: function(cellvalue, options, rowdata) {
                    return "<a style='cursor:pointer;' class='btn btn-primary' onclick='vm.statistics("+ rowdata.userid +")'>" +
                        "统计</a>";
                }}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

    $.get(baseURL + "sys/agentshopbus/getBuss/", function(r){
        var html=' <select id="businessIds" class="form-control" style="font-size: 15px">'
        for(var i=0;i<r.list.length;i++){
            html+='<option value="'+r.list[i].busSn+'">'+r.list[i].busName+'</option>;'
        }
        html+='</select>'
        $("#businessId").html(html);
    });
});
layui.use('upload', function(){
    var upload = layui.upload;
});
layui.use('element', function(){
    var element = layui.element;
});

$.get(baseURL + "sys/agentshopbus/getBuss/", function(r){
    var html=' <select id="adminBusParents" class="form-control" style="font-size: 15px">'
    for(var i=0;i<r.list.length;i++){
        html+='<option value="'+r.list[i].busSn+'">'+r.list[i].busName+'</option>;'
    }
    html+='</select>'
    $("#adminBusParent").html(html);
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            name: null,
            address:null,
            agent:null,
            businessId: null,
            district: null,
            status: null
        },
        qcx: {
            shopName: null,
            shopPhone: null,
            status: null
        },
        qxz: {
            adminName: null,
            adminPhone:null,
            adminParent: null,
            businessId: null,
            status: null
        },
        qcxl: {
            shopName: null,
            shopPhone: null,
            status: null
        },
        qxzl: {
            adminName: null,
            adminPhone:null,
            adminParent: null,
            businessId: null,
            status: null
        },
        qcxll: {
            shopName: null,
            shopPhone: null,
            status: null
        },
		showList: true,
		title: null,
        role: {},
		merchant: {
            accuracy: null,
            latitude: null,
            sysUserId: null,
            sysUserName: null
        },
        agentShopBus: {
            busName: null
        },
        agent: {
            shopName: null
        },
        agentAdmincx: {
            agentcxx: null
        },
        shopAdmincx: {
            useridcx: null
        },
        dlstj:{
            orderSn: null,
            userid: null
        }
	},
    role: {},
    merchant: {
        accuracy: null,
        latitude: null,
        sysUserId: null,
        sysUserName: null
    },
    agentShopBus: {
        busName: null
    },
    agent: {
        shopName: null
    },
	methods: {
		query: function () {
			vm.reload();
		},
        queryAdminCX: function () {
            vm.reloadAdminCX();
        },
        queryAdminXZ: function () {
            vm.reloadAdminXZ();
        },
        queryAdminCXLast: function () {
            vm.reloadAdminCXLast();
        },
        queryShopAdminLast: function () {
            vm.reloadShopAdminLast();
        },
        queryShopAdminCXLast: function () {
            vm.reloadShopAdminCXLast();
        },
        queryMerchantTj:function () {
            vm.reloadMerchantTj();
        },
		add: function(){
            // vm.getRole();
			vm.showList = false;
			vm.title = "新增";
			vm.merchant = {
                accuracy: null,
                latitude: null,
                sysUserId: null,
                sysUserName: null
            };
            vm.merchant.chargingType=0;
            vm.merchant.chargingCompany="小时"
            vm.merchant.chargingStandardTime="每1小时收费0.001元";
            vm.merchant.freeTime="3000 分钟";
            vm.merchant.consume="1元";//每日最高消费
            vm.merchant.lineOne="0.1元";
            vm.merchant.lineTwo="0.2元";
            vm.merchant.lineThree="0.3元";
            vm.merchant.lineFour="0.4元";
            vm.merchant.lineFive="0.5元";
            vm.merchant.lineSix="";
            vm.merchant.lineTwelve="";

            $("#xzShopImg").show()
            var upload = layui.upload; //得到 upload 对象
            console.log(upload);
            upload.render({
                elem: '#xzShopImg'
                ,url: baseURL + 'sys/merchant/uploadImg/'
                ,auto: false //选择文件后不自动上传
                ,field : 'file'
                ,bindAction: '#isShopImg' //指向一个按钮触发上传
                ,choose: function(obj){
                    var files = obj.pushFile();
                    if (files.size>1024*1024*2) {
                        layer.msg("上传的图片不允许超过2M")
                        return;
                    }else if (!files.type ==='jpg'||!files.type ==='png') {
                        return;
                    }
                    obj.preview(function(index, file, result){
                        $("#xsShopImg").html('<img src="'+ result +'" width="500px"   alt="'+ file.name +'">')
                    });
                }
                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                }
                ,done: function(res, index, upload){ //上传后的回调
                    if(res.code==0){
                        layer.closeAll()
                        layer.msg("上传成功")
                        $("#shopImg").val(res.fileName);
                    }
                }
            })

            $("#xzShopLogo").show()
            // var uploadLogo = layui.upload; //得到 upload 对象
            console.log(upload);
            upload.render({
                elem: '#xzShopLogo'
                ,url: baseURL + 'sys/merchant/uploadLogo/'
                ,auto: false //选择文件后不自动上传
                ,field : 'file'
                ,bindAction: '#isShopLogo' //指向一个按钮触发上传
                ,choose: function(obj){
                    var files = obj.pushFile();
                    obj.preview(function(index, file, result){
                        $("#xsShopLogo").html('<img src="'+ result +'" width="500px"   alt="'+ file.name +'">')
                    });
                }
                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                }
                ,done: function(res, index, upload){ //上传后的回调
                    if(res.code==0){
                        layer.closeAll()
                        layer.msg("上传成功")
                        $("#shopLogo").val(res.fileName);
                    }
                }
            })

		},
		update: function (id) {
            // vm.getRole();
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
        statistics :function (userid) {
            vm.dlstj.userid = userid;
            $.jgrid.gridUnload("jqGridAdddls");
            $("#jqGridAdddls").jqGrid({
                url: baseURL + 'sys/shoporder/merchantlist',
                datatype: "json",
                colModel: [
                    { label: '用户', name: 'userId', index: 'USER_ID', width: 150,formatter: function(cellvalue, options, rowdata) {
                            var username="" ;
                            $.ajax({
                                type: "POST",
                                async:false,
                                url: baseURL + "sys/users/info/"+rowdata.userId,
                                success: function(r){
                                    username = r.users.username;

                                }
                            });
                            return username;
                        }
                    },
                    { label: '订单状态', name: 'orderStatus', width: 130, formatter: function(value, options, row){
                            if (value ==0) {
                                return '<span class="label label-danger">租借中</span>' ;
                            }  else if (value ==1) {
                                return '<span class="label label-danger">已完成</span>' ;
                            }  else if (value ==2) {
                                return '<span class="label label-danger">已撤销</span>' ;
                            }
                        }},
                    { label: '二维码编号', name: 'qcode', index: 'qcode', width: 150},
                    { label: '使用时长', name: 'useduration', index: 'useDuration', width: 110 },
                    { label: '实付金额', name: 'actualAmount', index: 'actual_amount', width: 110 }

                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerdls",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                postData : {userid:userid},
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAdddls").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            $('#myModaldls').modal();
        },
		saveOrUpdate: function (event) {
		    $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function() {
                vm.merchant.province=$("#provinceCode").val()
                vm.merchant.city=$("#cityCode").val()
                vm.merchant.district=$("#districtCode").val()
                // vm.merchant.agent = $("#beAgent").text();
                // vm.merchant.businessid = $("#beBussness").text();
                // vm.merchant.userid =$("#agentAdmin").text();
                vm.merchant.startTime =$("#startTime").val();
                vm.merchant.endTime =$("#endTime").val();
                if ("小时"==vm.merchant.chargingCompany) {
                    vm.merchant.chargingCompany = 0;
                }
                var url = vm.merchant.id == null ? "sys/merchant/save" : "sys/merchant/update";
                vm.merchant.shopImg = $("#shopImg").val();
                vm.merchant.shopLogo = $("#shopLogo").val();
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.merchant),
                    success: function(r){
                        if(r.code === 0){
                             layer.msg("操作成功", {icon: 1});
                             vm.reload();
                             $('#btnSaveOrUpdate').button('reset');
                             $('#btnSaveOrUpdate').dequeue();
                        }else{
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
			});
		},
        getChargingType: function() {
            if ("0"==vm.merchant.chargingType) {
                $("#unit").hide();
                $("#inputUnit").show();
                $("#hour").hide();
                $("#minute").hide();
                $("#charingInput").val('每1小时收费0.001元');
                $("#howLongTimeInput").val('3000 分钟');
                $("#maxPayInput").val('1元');
                $("#1HourInput").val('0.1元');
                $("#2HourInput").val('0.2元');
                $("#3HourInput").val('0.3元');
                $("#4HourInput").val('0.4元');
                $("#5HourInput").val('0.5元');
                $("#6HourInput").val('');
                $("#12HourInput").val('');

                $("#charingInput").attr('disabled', 'disabled');
                $("#howLongTimeInput").attr('disabled', 'disabled');
                $("#maxPayInput").attr('disabled', 'disabled');
                $("#1HourInput").attr('disabled', 'disabled');
                $("#2HourInput").attr('disabled', 'disabled');
                $("#3HourInput").attr('disabled', 'disabled');
                $("#4HourInput").attr('disabled', 'disabled');
                $("#5HourInput").attr('disabled', 'disabled');
                $("#6HourInput").attr('disabled', 'disabled');
                $("#12HourInput").attr('disabled', 'disabled');
            }else {
                $("#unit").show();
                $("#inputUnit").hide();
                $("#charingInput").removeAttr('disabled');
                $("#howLongTimeInput").removeAttr('disabled');
                $("#maxPayInput").removeAttr('disabled');
                $("#1HourInput").removeAttr('disabled');
                $("#2HourInput").removeAttr('disabled');
                $("#3HourInput").removeAttr('disabled');
                $("#4HourInput").removeAttr('disabled');
                $("#5HourInput").removeAttr('disabled');
                $("#6HourInput").removeAttr('disabled');
                $("#12HourInput").removeAttr('disabled');

                $("#charingInput").val('');
                $("#howLongTimeInput").val('');
                $("#maxPayInput").val('');
                $("#1HourInput").val('');
                $("#2HourInput").val('');
                $("#3HourInput").val('');
                $("#4HourInput").val('');
                $("#5HourInput").val('');
                $("#6HourInput").val('');
                $("#12HourInput").val('');

                if("0"==vm.merchant.chargingCompany){
                    $("#hour").show();
                    $("#minute").hide();
                    $("#minuteInput").removeAttr('disabled');
                }else if("1"==vm.merchant.chargingCompany) {
                    $("#hour").hide();
                    $("#minute").show();
                    $("#minuteInput").removeAttr('disabled');
                }
            }
        },
        getHour: function() {
		    // if ("0"==vm.merchant.chargingCompany) {
		    //     $("#hour").show();
            //     $("#minute").hide();
            //     $("#hourInput").removeAttr('disabled');
            //
            // } else {
            //     $("#hour").hide();
            //     $("#minute").show();
            //     $("#minuteInput").removeAttr('disabled');
            // }
        },
		del: function (id) {
			var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定','取消'] //按钮
            }, function(){
               if(!lock) {
                    lock = true;
		            $.ajax({
                        type: "POST",
                        url: baseURL + "sys/merchant/deleteById",
                        contentType: "application/json",
                        data: JSON.stringify(id),
                        success: function(r){
                            if(r.code == 0){
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            }else{
                                layer.alert(r.msg);
                            }
                        }
				    });
			    }
             }, function(){
             });
		},
        addAdminCX: function () {
            $("#jqGridAddCX").jqGrid({
                url: baseURL + 'sys/agent/list',
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '代理商名称', name: 'shopName', index: 'SHOP_NAME', width: 80 },
                    { label: '代理商手机', name: 'shopPhone', index: 'SHOP_PHONE', width: 80 },
                    // { label: '代理模式 0 购买设备 1 投放设备', name: 'shopType', index: 'SHOP_TYPE', width: 80 },
                    { label: '代理模式', name: 'shopType', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">购买设备</span>' :
                                '<span class="label label-success">投放设备</span>';
                        }},
                    { label: '代理商上级', name: 'shopParent', index: 'SHOP_PARENT', width: 80 },
                    { label: '佣金百分比', name: 'shopRatio', index: 'SHOP_RATIO', width: 80 },
                    // { label: '0 可打开所属机柜 1 不可打开', name: 'isopen', index: 'isOPEN', width: 80 },
                    { label: '可打开所属机柜', name: 'isopen', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">是</span>' :
                                '<span class="label label-success">否</span>';
                        }},
                    // { label: '所属系统', name: 'sysSystem', index: 'SYS_SYSTEM', width: 80 },
                    // { label: '状态 0 正常 1 禁用', name: 'status', index: 'STATUS', width: 80 },
                    { label: '状态', name: 'status', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">正常</span>' :
                                '<span class="label label-success">异常</span>';
                        }},
                    // { label: '备注', name: 'remarks', index: 'REMARKS', width: 80 },
                    // { label: '创建时间', name: 'createdTime', index: 'CREATED_TIME', width: 80 },
                    // { label: '登录密码', name: 'loginPassword', index: 'LOGIN_PASSWORD', width: 80 }
                    { label: '操作', name: 'sy', width: 70,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseCX("+ rowdata.id +")'>" +
                                "选择</a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerCX",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddCX").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalCX').modal();
        },
        shopChooseCX:function (id) {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/agent/info/"+id,
                success: function(r){
                    $("#agentParentQueryCX").html("");
                    $("#agentParentQueryCX").append(r.agent.shopName);
                    vm.agentAdmincx.agentcxx=r.agent.id;

                }
            });
            $('#myModalCX').modal("hide");

        },
        addAdminCXLast: function () {
            $("#jqGridAddCXLast").jqGrid({
                url: baseURL + 'sys/agent/list',
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '代理商名称', name: 'shopName', index: 'SHOP_NAME', width: 80 },
                    { label: '代理商手机', name: 'shopPhone', index: 'SHOP_PHONE', width: 80 },
                    // { label: '代理模式 0 购买设备 1 投放设备', name: 'shopType', index: 'SHOP_TYPE', width: 80 },
                    { label: '代理模式', name: 'shopType', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">购买设备</span>' :
                                '<span class="label label-success">投放设备</span>';
                        }},
                    { label: '代理商上级', name: 'shopParent', index: 'SHOP_PARENT', width: 80 },
                    { label: '佣金百分比', name: 'shopRatio', index: 'SHOP_RATIO', width: 80 },
                    // { label: '0 可打开所属机柜 1 不可打开', name: 'isopen', index: 'isOPEN', width: 80 },
                    { label: '可打开所属机柜', name: 'isopen', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">是</span>' :
                                '<span class="label label-success">否</span>';
                        }},
                    // { label: '所属系统', name: 'sysSystem', index: 'SYS_SYSTEM', width: 80 },
                    // { label: '状态 0 正常 1 禁用', name: 'status', index: 'STATUS', width: 80 },
                    { label: '状态', name: 'status', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">正常</span>' :
                                '<span class="label label-success">异常</span>';
                        }},
                    // { label: '备注', name: 'remarks', index: 'REMARKS', width: 80 },
                    // { label: '创建时间', name: 'createdTime', index: 'CREATED_TIME', width: 80 },
                    // { label: '登录密码', name: 'loginPassword', index: 'LOGIN_PASSWORD', width: 80 }
                    { label: '操作', name: 'sy', width: 70,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseCXLast("+ rowdata.id +")'>" +
                                "选择</a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerCXLast",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddCXLast").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalCXLast').modal();
        },
        shopChooseCXLast:function (id) {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/agent/info/"+id,
                success: function(r){
                    $("#agentParentQueryCX2").html("");
                    $("#agentParentQueryCX2").append(r.agent.shopName);
                }
            });
            $('#myModalCXLast').modal("hide");

        },

        addShopAdminCXLast: function () {
            $("#jqGridAddShopAdminCXLast").jqGrid({
                url: baseURL + 'sys/agent/list',
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '代理商名称', name: 'shopName', index: 'SHOP_NAME', width: 80 },
                    { label: '代理商手机', name: 'shopPhone', index: 'SHOP_PHONE', width: 80 },
                    // { label: '代理模式 0 购买设备 1 投放设备', name: 'shopType', index: 'SHOP_TYPE', width: 80 },
                    { label: '代理模式', name: 'shopType', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">购买设备</span>' :
                                '<span class="label label-success">投放设备</span>';
                        }},
                    { label: '代理商上级', name: 'shopParent', index: 'SHOP_PARENT', width: 80 },
                    { label: '佣金百分比', name: 'shopRatio', index: 'SHOP_RATIO', width: 80 },
                    // { label: '0 可打开所属机柜 1 不可打开', name: 'isopen', index: 'isOPEN', width: 80 },
                    { label: '可打开所属机柜', name: 'isopen', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">是</span>' :
                                '<span class="label label-success">否</span>';
                        }},
                    // { label: '所属系统', name: 'sysSystem', index: 'SYS_SYSTEM', width: 80 },
                    // { label: '状态 0 正常 1 禁用', name: 'status', index: 'STATUS', width: 80 },
                    { label: '状态', name: 'status', width: 50, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">正常</span>' :
                                '<span class="label label-success">异常</span>';
                        }},
                    // { label: '备注', name: 'remarks', index: 'REMARKS', width: 80 },
                    // { label: '创建时间', name: 'createdTime', index: 'CREATED_TIME', width: 80 },
                    // { label: '登录密码', name: 'loginPassword', index: 'LOGIN_PASSWORD', width: 80 }
                    { label: '操作', name: 'sy', width: 50,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseShuoAdminCXLast("+ rowdata.id +")'>" +
                                "选择</a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerShopAdminCXLast",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddShopAdminCXLast").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalShopAdminCXLast').modal();
        },
        shopChooseShuoAdminCXLast:function (id) {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/agent/info/"+id,
                success: function(r){
                    $("#agentParentQueryAdminCX2").html("");
                    $("#agentParentQueryAdminCX2").append(r.agent.shopName);
                }
            });
            $('#myModalShopAdminCXLast').modal("hide");

        },

        addAgentXZ: function () {
            $("#jqGridAddXZ").jqGrid({
                url: baseURL + 'sys/agentshopadmin/list',
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '管理员名称', name: 'adminName', index: 'ADMIN_NAME', width: 80 },
                    { label: '管理员手机', name: 'adminPhone', index: 'ADMIN_PHONE', width: 80 },
                    // { label: '所属代理商', name: 'adminParent', index: 'ADMIN_PARENT', width: 80 },
                    // { label: '所属业务员', name: 'adminBusParent', index: 'ADMIN_BUS_PARENT', width: 80 },
                    { label: '所属代理商', name: 'adminParent', index: 'ADMIN_PARENT', width: 80,formatter: function(cellvalue, options, rowdata) {
                            var shopName ;
                            $.ajax({
                                type: "POST",
                                async:false,
                                url: baseURL + "sys/agent/info/"+rowdata.adminParent,
                                success: function(r){
                                    if (null == r.agent) {
                                        shopName="";
                                    } else {
                                        shopName = r.agent.shopName;
                                    }
                                }
                            });
                            return shopName;
                        }
                    },
                    { label: '所属业务员', name: 'adminBusParent', index: 'ADMIN_BUS_PARENT', width: 80,formatter: function(cellvalue, options, rowdata) {
                            var shopName ;
                            $.ajax({
                                type: "POST",
                                async:false,
                                url: baseURL + "sys/agentshopbus/infobus/"+rowdata.adminBusParent,
                                success: function(r){
                                    if (null == r.agentShopBus) {
                                        shopName="";
                                    } else {
                                        shopName = r.agentShopBus.busName;
                                    }

                                }
                            });
                            return shopName;
                        }
                    },
                    { label: '佣金百分比', name: 'adminRatio', index: 'ADMIN_RATIO', width: 80 },
                    // { label: '可打开所属机柜', name: 'adminOpen', index: 'ADMIN_OPEN', width: 80 },
                    { label: '可打开所属机柜', name: 'adminOpen', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">是</span>' :
                                '<span class="label label-success">否</span>';
                        }},
                    // { label: '状态', name: 'status', index: 'STATUS', width: 80 },
                    { label: '状态', name: 'status', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">正常</span>' :
                                '<span class="label label-success">禁止</span>';
                        }},
                    { label: '操作', name: 'sy', width: 70,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseXZ("+ rowdata.id +")'>" +
                                "选择</a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerXZ",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddXZ").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalXZ').modal();
        },
        shopChooseXZ:function (id) {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/agentshopadmin/info/"+id,
                success: function(r){
                    $("#agentAdmin").html("");
                    $("#beAgent").html("");
                    $("#beBussness").html("");
                    // $("#agentAdmin").append(r.agentShopAdmin.id);
                    $("#agentAdmin").append(r.agentShopAdmin.adminName);
                    vm.merchant.userid=r.agentShopAdmin.id;

                    //代理商
                    $.ajax({
                        type: "POST",
                        async:false,
                        url: baseURL + "sys/agent/info/"+r.agentShopAdmin.adminParent,
                        success: function(r1){
                            $("#beAgent").append(r1.agent.shopName);
                            vm.merchant.agent=r1.agent.id;
                        }
                    });

                    //业务员
                    $.ajax({
                        type: "POST",
                        async:false,
                        url: baseURL + "sys/agentshopbus/info/"+r.agentShopAdmin.adminBusParent,
                        success: function(r2){
                            $("#beBussness").append(r2.agentShopBus.busName);
                            vm.merchant.businessid=r2.agentShopBus.id;
                        }
                    });
                    // $("#beAgent").append(r.agentShopAdmin.adminParent);
                    // $("#beBussness").append(r.agentShopAdmin.adminBusParent);
                }
            });
            $('#myModalXZ').modal("hide");

        },
        checkedShopAdmin : function () {
            $("#jqGridAddShopAdminCX").jqGrid({
                url: baseURL + 'sys/agentshopadmin/list',
                datatype: "json",
                colModel: [
                    // { label: 'id', name: 'id', index: 'ID', width: 50, key: true },
                    { label: '管理员名称', name: 'adminName', index: 'ADMIN_NAME', width: 80 },
                    { label: '管理员手机', name: 'adminPhone', index: 'ADMIN_PHONE', width: 80 },
                    // { label: '所属代理商', name: 'adminParent', index: 'ADMIN_PARENT', width: 80 },
                    // { label: '所属业务员', name: 'adminBusParent', index: 'ADMIN_BUS_PARENT', width: 80 },
                    { label: '所属代理商', name: 'adminParent', index: 'ADMIN_PARENT', width: 80,formatter: function(cellvalue, options, rowdata) {
                            var shopName ;
                            $.ajax({
                                type: "POST",
                                async:false,
                                url: baseURL + "sys/agent/info/"+rowdata.adminParent,
                                success: function(r){
                                    if (null == r.agent) {
                                        shopName="";
                                    } else {
                                        shopName = r.agent.shopName;
                                    }
                                }
                            });
                            return shopName;
                        }
                    },
                    { label: '所属业务员', name: 'adminBusParent', index: 'ADMIN_BUS_PARENT', width: 80,formatter: function(cellvalue, options, rowdata) {
                            var shopName ;
                            $.ajax({
                                type: "POST",
                                async:false,
                                url: baseURL + "sys/agentshopbus/infobus/"+rowdata.adminBusParent,
                                success: function(r){
                                    if (null == r.agentShopBus) {
                                        shopName="";
                                    } else {
                                        shopName = r.agentShopBus.busName;
                                    }
                                }
                            });
                            return shopName;
                        }
                    },
                    { label: '佣金百分比', name: 'adminRatio', index: 'ADMIN_RATIO', width: 80 },
                    // { label: '可打开所属机柜', name: 'adminOpen', index: 'ADMIN_OPEN', width: 80 },
                    { label: '可打开所属机柜', name: 'adminOpen', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">是</span>' :
                                '<span class="label label-success">否</span>';
                        }},
                    // { label: '状态', name: 'status', index: 'STATUS', width: 80 },
                    { label: '状态', name: 'status', width: 80, formatter: function(value, options, row){
                            return value === 0 ?
                                '<span class="label label-danger">正常</span>' :
                                '<span class="label label-success">禁止</span>';
                        }},
                    { label: '操作', name: 'sy', width: 70,align:'center',formatter: function(cellvalue, options, rowdata) {
                            return "<a style='cursor:pointer;' onclick='vm.shopChooseAdmin("+ rowdata.id +")'>" +
                                "选择</a>&nbsp;&nbsp;&nbsp;&nbsp;" ;
                        }}
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList : [10,30,50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth:true,
                multiselect: true,
                pager: "#jqGridPagerShopAdminCX",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //隐藏grid底部滚动条
                    $("#jqGridAddShopAdminCX").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
                }
            });
            // vm.queryGroup();
            $('#myModalShopAdmin').modal();
        },
        shopChooseAdmin:function (id) {
            $.ajax({
                type: "POST",
                async:false,
                url: baseURL + "sys/agentshopadmin/info/"+id,
                success: function(r){
                    $("#shopAdministrator").html("");
                    $("#shopAdministrator").append(r.agentShopAdmin.adminName);
                    vm.shopAdmincx.useridcx=r.agentShopAdmin.id;
                }
            });
            $('#myModalShopAdmin').modal("hide");

        },
        // getSysUser: function () {
        //     $.ajax({
        //         type: "POST",
        //         url: baseURL + "sys/merchant/getSysUsers",
        //         success: function (r) {
        //             console.log(r);
        //             if (r.code == 0) {
        //                 vm.user = r.data;
        //             } else {
        //                 layer.alert(r.msg);
        //             }
        //         }
        //     });
        //     console.log(vm);
        // },
        // setUsername: function (id) {
        //     for (let i = 0; i < vm.user.length; i++) {
        //         if (id == vm.user[i].userId) {
        //             vm.merchant.roleName = vm.user[i].username;
        //         }
        //     }
        //     console.log(vm);
        // },
		getInfo: function(id){
			$.get(baseURL + "sys/merchant/info/"+id, function(r){
                $.ajax({
                    type: "POST",
                    async:false,
                    url: baseURL + "sys/agentshopadmin/info/"+r.merchant.userid,
                    success: function(r){
                        $("#agentAdmin").text(r.agentShopAdmin.adminName);

                        //代理商
                        $.ajax({
                            type: "POST",
                            async:false,
                            url: baseURL + "sys/agent/info/"+r.agentShopAdmin.adminParent,
                            success: function(r1){
                                $("#beAgent").text(r1.agent.shopName);
                            }
                        });

                        //业务员
                        $.ajax({
                            type: "POST",
                            async:false,
                            url: baseURL + "sys/agentshopbus/info/"+r.agentShopAdmin.adminBusParent,
                            success: function(r2){
                                $("#beBussness").text(r2.agentShopBus.busName);
                            }
                        });
                    }
                });
                vm.merchant = r.merchant;
            });
		},
		reload: function (event) {
			vm.showList = true;
            // vm.q.adminParent = $("#agentParentQueryCX").text();
            // vm.q.userid = $("#shopAdministrator").text();
            // vm.merchant.agent=r.agent.id;
            vm.q.agent = vm.agentAdmincx.agentcxx;
            vm.q.userid = vm.shopAdmincx.useridcx;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData: {'name' : vm.q.name,
                    'address': vm.q.address
                },
                page:page
            }).trigger("reloadGrid");
		},
        reloadAdminCX: function (event) {
            var page = $("#jqGridAddCX").jqGrid('getGridParam','page');
            $("#jqGridAddCX").jqGrid('setGridParam',{
                postData: {'name' : vm.qcx.name,
                    'district': vm.qcx.district,
                    'status': vm.qcx.status,
                    'businessId': vm.qcx.businessId,
                    'agent': vm.qcx.agent
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadAdminXZ: function (event) {
            vm.qxz.adminParent = $("#agentParentQueryCX2").text();
            var page = $("#jqGridAddXZ").jqGrid('getGridParam','page');
            $("#jqGridAddXZ").jqGrid('setGridParam',{
                postData: {'adminName' : vm.qxz.adminName,
                    'adminPhone': vm.qxz.adminPhone,
                    'status': vm.qxz.status,
                    'adminParent': vm.qxz.adminParent,
                    'adminBusParent': vm.qxz.businessId
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadAdminCXLast: function (event) {
            var page = $("#jqGridAddXZLast").jqGrid('getGridParam','page');
            $("#jqGridAddXZLast").jqGrid('setGridParam',{
                postData: {'status': vm.qcx.status,
                    'shopName': vm.qcx.shopName,
                    'shopPhone': vm.qcx.shopPhone
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadShopAdminCXLast: function (event) {
            var page = $("#jqGridAddXZLast").jqGrid('getGridParam','page');
            $("#jqGridAddXZLast").jqGrid('setGridParam',{
                postData: {'status': vm.qcxll.status,
                    'shopName': vm.qcxll.shopName,
                    'shopPhone': vm.qcxll.shopPhone
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadShopAdminLast: function (event) {
            vm.qxzl.adminParent = $("#agentParentQueryAdminCX2").text();
            var page = $("#jqGridAddShopAdminCX").jqGrid('getGridParam','page');
            $("#jqGridAddShopAdminCX").jqGrid('setGridParam',{
                postData: {'adminName' : vm.qxzl.adminName,
                    'adminPhone': vm.qxzl.adminPhone,
                    'status': vm.qxzl.status,
                    'adminParent': vm.qxzl.adminParent,
                    'adminBusParent': vm.qxzl.businessId
                },
                page:page
            }).trigger("reloadGrid");
        },
        reloadMerchantTj: function (event) {
            var page = $("#jqGridAdddls").jqGrid('getGridParam','page');
            $("#jqGridAdddls").jqGrid('clearGridData');  //清空表格
            $("#jqGridAdddls").jqGrid('setGridParam',{
                postData: {'userid': vm.dlstj.userid,
                    'orderSn': vm.dlstj.orderSn
                },
                page:page
            }).trigger("reloadGrid");
        }
	}
});